/*
 * cardtest2.c
 *
 *  Created on: Jan 26, 2014
 *      Author: Charles_OSU
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "rngs.h"
#include <math.h>

#define DEBUG 0


// prototypes
// prototypes
int testvillage(int currentPlayer, struct gameState *state);

int testvillage(int currentPlayer, struct gameState *state) {

        int i;
        int result;
       // int saveHandCount = state->handCount[currentPlayer];
        int handPos = floor(Random() * state->handCount[currentPlayer]);
       // int saveActionCount = state->numActions;

        struct gameState gameStateTest;
        memcpy(&gameStateTest, state, sizeof(struct gameState));

        SelectStream(2);
        PutSeed(3);

        result = cardEffect(village, 0, 0, 0, state, handPos, 0);

        SelectStream(2);
        //+1 Cards
        for (i = 0; i < 1; i++) {
                drawCard(currentPlayer, &gameStateTest);
        }

        //+2 Actions
        gameStateTest.numActions = gameStateTest.numActions + 2;


        //discard card from hand
        discardCard(handPos, currentPlayer, &gameStateTest, 0);
        //assert(memcmp(&gameStateTest, state, sizeof(struct gameState)) == 0);
        //assert(state->numActions == saveActionCount + 2);
       // assert(state->handCount[currentPlayer] == saveHandCount + 2);
       // assert (result == 0);

        return 0;

}

/*
 * Using a common template to call and setup tests for each card since we must
 * call all cards as if they are in the Cardeffect or their own function which
 * simply means that we should call them from Cardeffect. I have started to run out
 * of time so I have resorted to the slopy way of just doing asserts instead of the
 * more proper way i did them in unittest1..unittest3
 */
int main() {
	// Declare variable to use
	  int n;
	  int i;
	  int p;
	  int testNums = 0;
	  struct gameState gameStateTest;

	  // Print a headder
         printf ("Testing cardEffect() with village card\n");
         printf ("RANDOM TESTS\n");

         // Seed our game
       SelectStream(3);
       PutSeed(3);

       // Setup number of tests
       for (n = 0; n < 3000; n++) {
       SelectStream(3);
       for (i = 0; i < sizeof(struct gameState); i++) {
       ((char*)&gameStateTest)[i] = floor(Random() * 256);
       }

               p = floor(Random() * MAX_PLAYERS);
               gameStateTest.whoseTurn = p;
               gameStateTest.deckCount[p] = floor(Random() * MAX_DECK);
               gameStateTest.discardCount[p] = floor(Random() * MAX_DECK);
               gameStateTest.handCount[p] = floor(Random() * MAX_HAND);
               gameStateTest.playedCardCount = floor(Random() * MAX_DECK);

               testvillage(p, &gameStateTest);
               testNums += 1;
        }

       // If we get to here it means we kept running and did not crash the program
        // so our tests must have run now let's see how many errors we got.
          printf ("All Tests ran for testvillage\n");
          printf ("%d RANDOM TESTS.\n", testNums);


        return 0;

}

